package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: qingtao
 * @Date 2022/3/22 20:03
 */
public interface ShoppingCartMapper {

    /**
     * 根据Uid Dis Sid
     * @param shoppingCart
     * @return
     */
    ShoppingCart findUidAndDisOrSid(ShoppingCart shoppingCart);

    /**
     * 添加购物车项
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart values(null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void save(ShoppingCart shoppingCart);

    /**
     * 更新购物项
     * @param shoppingCartOne
     */
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void update(ShoppingCart shoppingCartOne);

    /**
     * 根据userId查询
     * @param userId
     * @return
     */
    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> findCartByUserId(Long userId);

    /**
     * 清空购物车
     * @param userId
     * @return
     */
    @Delete("delete from shopping_cart where user_id=#{userId}")
    Integer clear(Long userId);
}
